#pragma once
#include <opencv2/core.hpp>
#include <opencv2/opencv.hpp>
#include <opencv2/imgcodecs.hpp>
#include <opencv2/highgui.hpp>

using namespace cv;
using namespace std;

const int MaxLab = 70;
struct Pos
{
	int r;
	int c;
};

class Union_Find
{	
private:
	Mat B;
	Mat LB;
	int label;
	int PARENT[MaxLab + 1];

	void initialize();
	Pos* prior_neighbors(int row, int col, int *c);
	int isempty(Pos *A, int c);
	int* labels(Pos *A, int c, int *lc);
	int min(int l[], int c);
	void _union(int X, int Y, int PARENT[]);
	int find(int X, int PARENT[]);
public:
	Union_Find();
	~Union_Find();

	void classical_with_union_find(Mat B, Mat LB);
};

